from ast import *

class Functions:
 def __init__(self):
  self.userFunc={}
  self.builtins={
".":([ExpressionNode],[]),
"count":([],[IntExpressionNode]),
"drop":([ExpressionNode],[]),
"dup":([ExpressionNode],[ExpressionNode],ExpressionNode),
"swap":([ExpressionNode,ExpressionNode],[ExpressionNode,ExpressionNode]),
"rot":([ExpressionNode,ExpressionNode,ExpressionNode],[ExpressionNode,ExpressionNode,ExpressionNode]),
"dswap":([ExpressionNode,ExpressionNode,ExpressionNode,ExpressionNode],[ExpressionNode,ExpressionNode,ExpressionNode,ExpressionNode]),
"++":([NumaricExpressionNode],[NumaricExpressionNode]),
"--":([NumaricExpressionNode],[NumaricExpressionNode]),
"+":([NumaricExpressionNode,NumaricExpressionNode],[NumaricExpressionNode]),
 "-":([NumaricExpressionNode,NumaricExpressionNode],[NumaricExpressionNode]),
"*":([NumaricExpressionNode,NumaricExpressionNode],[NumaricExpressionNode]),
"/":([NumaricExpressionNode,NumaricExpressionNode],[NumaricExpressionNode]),
"<":([NumaricExpressionNode,NumaricExpressionNode],[BooleanExpressionNode]),
">":([NumaricExpressionNode,NumaricExpressionNode],[BooleanExpressionNode]),
"<=":([NumaricExpressionNode,NumaricExpressionNode],[BooleanExpressionNode]),
">=":([NumaricExpressionNode,NumaricExpressionNode],[BooleanExpressionNode]),
"==":([NumaricExpressionNode,NumaricExpressionNode],[BooleanExpressionNode]),
"z=":([NumaricExpressionNode],[BooleanExpressionNode]),
"mod":([NumaricExpressionNode,NumaricExpressionNode],[NumaricExpressionNode]),
",":([ExpressionNode],[]),
"?":([],[StringExpressionNode]),
	
}

  #is there a function called x?
 def isFunc(self, func): #takes string representing the name of the func.
  return self.builtins.has_key(func) or self.userFunc.has_key(func) #check the tables.

 #Ok, we have it, where is it?
 def GetFunc(self, func): #string with the name of the func.
  #which table?
  if self.userFunc.has_key(func): #check user funcs first in case builtin is overwritten.
   return self.userFunc[func] #return user func.
  elif self.builtins.has_key(func): #if it's a builtin,
   return self.builtins[func] #send it back.
  else: #oops, this isn't a func,
   raise Exception("Passed Function class invalid function.") #if we get here, the program itself has a problem, not just a programming error, so we die.
  
